<template>
	<view class="content">
		<view class="chat_box">
			<view class="" >
				<view class="real_chat_box" >
					<view v-for="(v,n) in msgArr">
						<view class="user_chat" v-if="v.is_user==1">
							<view>{{v.content}}</view>
							<image :src="userImg" mode=""></image>
						</view>
						<view class="com_chat" v-if="v.is_user==0">
							<image :src="imgUrl+'/static/wap/infoImg/kefu_o.png'" mode=""></image>
							<view>{{v.content}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部发送区域 -->
		<view class="feed_send">
			<!-- 左侧输入 -->
			<input v-model="content" placeholder="有什么话尽管说吧">
			<!-- 右侧发送 -->
			<view @click="setFeeback">
				<image :src="imgUrl+'/static/wap/infoImg/fabu@2x.png'"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import util from '../../static/util.js'
	export default {
		data() {
			return {
				imgUrl:util.globalData.imgPre,
				msgArr:[],
				type_id:'',
				id:'',
				content:'',
				userImg:''
			};
		},
		onLoad(option) {
			 const value = uni.getStorageSync('userInfo');
			 this.userImg=value.wechatInfo.headimgurl
			this.id=option.id
			this.render()
		},
		methods:{
			setFeeback(){
				var that=this;
				that.ajax({
					url:'/api/feedback/setFeeback',
					data:{
						type_id:this.type_id,
						content:this.content,
						is_first:0,
						parent_id:this.id
					},
					success:(res)=>{
						console.log(res);
						if(res.code !=200){
							uni.showToast({
								title:res.msg,
								icon:'none'
							})
							return
						}
						this.content=""
						this.render()
						setTimeout(() => {
							uni.navigateTo({
								url: "feedbackList"
							})
						}, 1000)
					}
				  })
			},
			render(){
				this.ajax({
					url:'api/feedback/getFeebackDetail',
					data:{
						feedback_id:this.id
					},
					success:(res)=>{ 
						if(res.code!=200){
							uni.showToast({
								title:res.msg,
								icon:"none"
							})
							return
						}
						this.msgArr=res.data
						this.type_id=res.data[0].type_id
					}
				  })
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		background-color: #F7F9FB;
	}
	.feed_send{
		display: flex;
		position: fixed;
		padding-top: 20rpx;
		bottom: 0;
		left: 0;
		right: 0;
		height: 72rpx;
		background-color: #fff;
		input{
			margin-top: 12rpx;
			padding: 0 40rpx;
			flex: 1;
			font-size: 26rpx;
		}
		view{ 
			width: 100rpx; 
			image{
				width: 54rpx;
				height: 54rpx;
			}
		}
	}
	.chat_box{
		height: 100vh;
		width: 100%;
		box-sizing: border-box;
		padding-bottom: 72rpx;
		background: #f7f9fb;
		overflow-y: auto;
		.real_chat_box{
			width: 100%;
			box-sizing: border-box;
			padding: 45rpx 26rpx 0 27rpx;
			.user_chat{
				display: flex;
				align-items: flex-start;
				justify-content: flex-end;
				margin-bottom: 80rpx;
				&>image{
					border-radius: 50%;
					width: 50rpx;
					height: 50rpx;
					margin-left: 25rpx;
					flex-shrink: 0;
				}
				&>view{
					max-width: 76.5%;
					padding: 22rpx 8rpx 19rpx 16rpx;
					font-size: 30rpx;
					background: #ffffff;
					border-radius: 10rpx;
					box-shadow: 0px 3px 21px 0px rgba(187,221,223,0.35);  
				}
				
			}
			.com_chat{
				display: flex;
				align-items: flex-start;
				justify-content: flex-start;
				margin-bottom: 80rpx;
				&>image{
					width: 50rpx;
					height: 50rpx;
					margin-right: 25rpx;
					flex-shrink: 0;
				}
				&>view{
					max-width: 76.5%;
					padding: 22rpx 8rpx 19rpx 16rpx;
					font-size: 30rpx;
					background: #D9EBED;
					border-radius: 10px;
				}
				
			}
		}
	}
</style>
